<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="test1"></div>

<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>

<!-- jsx转为js -->
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

<script type="text/babel">
    // 字符串的ref，存在效率问题
    class Person extends React.Component {
        input1
        state = {
            isHot:true
        }
        showData1 = () => {
            console.log(this.input1.value)
        }

        demo = () => {

            this.setState({isHot: !this.state.isHot})
        }

        saveInput = (c) => {
            this.input1 = c;
            console.log(this.input1)
        }

        // 内联回调和类绑定回调，都可以
        render() {
            let {isHot} = this.state;
            return (
                   <div>
                        <h2>{isHot ? "颜热": "凉爽"}</h2>
                       {/*<input id="input1" ref={
                           // 直接在ref标签里面定义，就是内联函数, 在更新过程中会回调两次
                           // 第一次渲染，会出现节点
                           (currentNode) => { // 传递的当前的节点对象，就是input这个节点
                               console.log(currentNode)  // 更新的时候，render要执行一次，第一次null（把原来的数据清空）， 第一次当前节点
                           }
                       } type="text" placeholder="点击按钮提示"/>*/}

                       {/*类绑定会避免调用二次*/}

                       <input id="input1" ref={
                          this.saveInput
                       } type="text" placeholder="点击按钮提示"/>

                       <button onClick={this.showData1}>点我提示数据</button>

                       <button onClick={this.demo}>切换天气</button>
                   </div>
            )
        }


    }

    ReactDOM.render(<Person name="tom1" age={18} sex="女"/>, document.getElementById("test1"))
</script>
</body>
</html>